#pragma once

#include <windef.h>
#include <boost/function.hpp>

#include "exports.hpp"




#pragma warning (push)
#pragma warning (disable: 4251)

/**
 * This class simplifies the installation of a window hook.
 * It can be used to intercept window messages.
 * Aimed at simplicity, the class accepts a boost functor that
 * can be bound to anything, even a member function.
 *
 * Use this class with caution as it may very well decrease performance
 * of the application when used with too many windows.
 *
 * However, this class may only be used in the main thread of the
 * application. It may, under no circumstances be used in \b any
 * other thread.
 *
 * @warning   do not use this class in multiple threads, it is not thread safe.
 *            The class will do a check and crash on purpose
 *            if the calling thread differs from the main thread.
 */
class HOOKS_API WindowHook
{
public:

	typedef boost::function<void (int,WPARAM,LPARAM)> WindowProc;

private:

	WindowProc m_windowProc;
	HWND       m_window;

public:

	/**
	* Register a WindowHook on the specified window.
	*
	* @param window    the window who's messages this hook shall intercept
	* @param wndPrco   functor that is called when a window message is being processed
	 */
	WindowHook(const WindowProc& windowProc, HWND window);
	~WindowHook();



	/**
	 * Get the window handle this hook listens on.
	 */
	HWND window() const;

	/**
	 * Call the window procedure.
	 */
	void windowProc(int message, WPARAM wParam, LPARAM lParam) const;
};
///////////////////////////////////////////////////////////////////////////////////////////////////

#pragma warning (pop)
